package com.boat.ai;

import com.boat.ai.domain.entity.AiAgent;
import com.boat.ai.domain.enums.LangEnum;
import com.boat.ai.domain.enums.ModelEnum;
import com.boat.ai.util.IdUtil;
import io.vertx.mutiny.ext.auth.User;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;

import java.time.Instant;

@Path("/hello")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ExampleResource {

    @Inject
    Logger log;

    @GET
    @Path("/{name}")
    @Transactional(rollbackOn = Exception.class,value = Transactional.TxType.REQUIRED)
    public AiAgent hello(@PathParam("name") String name) {
        log.infof("用户ID: %d 订单号: %s", 123, name);
//        OpenAiChatModel model = OpenAiChatModel.builder()
//                .baseUrl("http://139.59.125.71:3000/v1")
//                .apiKey("sk-hFTLLBHYuUuzbXOjHQmJDx1APfKrxa2ipWkk1BufXYzQQh2A")
//                .modelName("gpt-4o-mini")
//                .build();
//        String rs = model.chat("说一个故事");

        // creating a person
        AiAgent aiAgent = new AiAgent();
        aiAgent.id = IdUtil.getId();
        aiAgent.lang = LangEnum.ZH_CN;
        aiAgent.modelEnum = ModelEnum.OPEN_AI;
        aiAgent.prompt = "请生成一个%s的%s";
        aiAgent.createTime = Instant.now();
        aiAgent.updateTime = Instant.now();
        aiAgent.persist();
        return aiAgent;
    }

    @POST
    @Path("/users")
    public Response createUser(User user) {
        return Response.status(201)
                .entity(user)
                .build();
    }
}
